﻿
Namespace LightSwitchApplication

    Public Class CustomerDetail

        Private Sub Customer_Loaded(succeeded As Boolean)
            ' Write your code here.
            Me.SetDisplayNameFromEntity(Me.Customer)
        End Sub

        Private Sub Customer_Changed()
            ' Write your code here.
            Me.SetDisplayNameFromEntity(Me.Customer)
        End Sub

        Private Sub CustomerDetail_Saved()
            ' Write your code here.
            Me.SetDisplayNameFromEntity(Me.Customer)
        End Sub

        Private Sub CustomerDetail_InitializeDataWorkspace(saveChangesTo As System.Collections.Generic.List(Of Microsoft.LightSwitch.IDataService))
            ' Write your code here.
            If Me.Customer.Country Is Nothing Then
                Me.Customer.Country = "Australia"
            End If
        End Sub

        Private Sub NewAppointment_Execute()
            'Show a new appointment screen but pass the customer ID so it is automatically filled out
            Me.Application.ShowCreateNewAppointment(Me.Customer.Id)
        End Sub

        Private Sub ShowMap_Execute()
            Me.Application.ShowMapScreen(Me.Customer.FullAddress)
        End Sub

        Private Sub ShowMap_CanExecute(ByRef result As Boolean)
            result = (Me.Customer.FullAddress <> "")
        End Sub

        Private Sub CustomerDetail_Saving(ByRef handled As Boolean)
            ' Write your code here.
            Dim userDetails = Me.DataWorkspace.ApplicationData.GetUserByUsername(Me.Application.User.Name)
            Me.Customer.User = userDetails.FirstOrDefault
        End Sub
    End Class

End Namespace